package com.novellotus.iov.carvice.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.novellotus.iov.carvice.R;
import com.novellotus.iov.carvice.activity.DailyAttentionActivity;
import com.novellotus.iov.carvice.activity.DailyMaintenanceActivity;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Rich on 2017/12/25.
 */

public class HomePageTipsAdapter extends RecyclerView.Adapter<HomePageTipsAdapter.TipsHolder> {

    Context context;

    public HomePageTipsAdapter(Context context) {
        this.context = context;
    }

    @Override
    public TipsHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_home_tips, null);
        return new TipsHolder(view);
    }

    @Override
    public void onBindViewHolder(TipsHolder holder, int position) {
        switch (position) {
            case 0:
                holder.img_background.setBackgroundResource(R.mipmap.banner_01);
                holder.img_background.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent intent = new Intent(context, DailyAttentionActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 1:
                holder.img_background.setBackgroundResource(R.mipmap.banner_02);
                holder.img_background.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent intent = new Intent(context, DailyMaintenanceActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
        }

    }

    @Override
    public int getItemCount() {
        return 2;
    }

    class TipsHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.img_background)
        ImageView img_background;

        TipsHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
